using System;
using System.Globalization;

namespace jSLCore.Client.Presentation.jBinding.BaseConverters
{
    public class jStringToFirstNSymbolsConverter : jChainConverter
    {
        private int _resultStringLength = 50;
        public int ResultStringLength
        {
            get { return _resultStringLength; }
            set { _resultStringLength = value; }
        }

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)return null;

            var str = value.ToString();
                if (ResultStringLength < str.Length) 
            {
                
                return str.Substring(0,ResultStringLength);
            }
            return value;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}